<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>商品页</title>
  <link rel="stylesheet" type="text/css" th:href="@{/static/layui-v2.6.13/layui/css/layui.css}"/>
  <script type="text/javascript" th:src="@{/static/js/jquery-1.9.1.min.js}"></script>
  <script type="text/javascript" th:src="@{/static/layui-v2.6.13/layui/layui.js}"></script>
</head>
<body>
<div class="layui-card">
  <div class="layui-card-header" align="center">购物车</div>
  <div class="layui-card-body">
    <div align="right">
      <label class="layui-btn layui-btn-primary">全选<input type="checkbox" onclick="checkAll(this)"></label>
      <button type="button" onclick="buy()" class="layui-btn layui-btn-primary">提交订单</button>
      <button type="button" onclick="del()" class="layui-btn layui-btn-primary">移出购物车</button>
    </div>
    <table class="layui-table">
      <tr th:each="good:${cart}">
        <td><input type="checkbox" th:value="${good.id}" name="xun"></td>
        <td th:text="${good.gName}"></td>
        <td th:text="'单价: '+${good.gPrice}"></td>
        <td th:text="'数量: '+${good.count}"></td>
        <td th:text="'总金额: '+${good.money}"></td>
      </tr>
    </table >
  </div>
</div>

</body>
<script>
  function checkAll(obj){
    if(obj.checked==true){
      var all = document.getElementsByName("xun");
      for(var i = 0; i < all.length; i++){
        all[i].checked=true;
      }
    }
    else{
      var all = document.getElementsByName("xun");
      for(var i = 0; i < all.length; i++){
        all[i].checked=false;
      }
    }
  }
  function buy(){
    var params = "";
    var all = document.getElementsByName("xun");
    for(var i = 0; i < all.length; i++){
      if(all[i].checked == true){
        params += all[i].value + ",";
      }
    }
    location.href = "submit?ids="+params.substr(0,params.length-1);
  }
  function del(){
    var params = "";
    var all = document.getElementsByName("xun");
    for(var i = 0; i < all.length; i++){
      if(all[i].checked == true){
        params += all[i].value + ",";
      }
    }
    location.href = "delete?ids="+params.substr(0,params.length-1);
  }
</script>
</html>